local zhiheng = fk.CreateSkill {

  name = "joyex__zhiheng",

  tags = {  },

}



zhiheng:addEffect("active", {
  name = "joyex__zhiheng",
  anim_type = "drawcard",
  min_card_num = 1,
  card_filter = function(self, player, to_select, selected)
    return not player:prohibitDiscard(Fk:getCardById(to_select))
  end,
  target_num = 0,
  can_use = function(self, player)
    return player:usedSkillTimes(zhiheng.name, Player.HistoryPhase) < 1 + player:getMark("joyex__zhiheng-phase")
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local hand = player:getCardIds(Player.Hand)
    local more = #hand > 0 and table.every(hand, function(id) return table.contains(effect.cards, id) end)
    room:throwCard(effect.cards, zhiheng.name, player, player)
    if player.dead then return end
    local cards = player:drawCards(#effect.cards + (more and 1 or 0), zhiheng.name)
    if player:usedSkillTimes(zhiheng.name, Player.HistoryPhase) == 1
    and table.every(cards, function(id) return Fk:getCardById(id).sub_type ~= Card.SubtypeDelayedTrick end) then
      room:addPlayerMark(player, "joyex__zhiheng-phase")
    end
    if player:usedSkillTimes(zhiheng.name, Player.HistoryPhase) == 2
    and table.every(cards, function(id) return Fk:getCardById(id).type == Card.TypeBasic end) then
      room:addPlayerMark(player, "joyex__zhiheng-phase")
    end
  end
})

return zhiheng